import tkinter as tk
from database import Database
from auth import AuthManager
from main_ui import MainUI

class RabbitInfoSystem:
    def __init__(self, root):
        self.root = root
        self.root.title("小兔信息管理系统")
        self.root.geometry("1000x700")
        
        # 初始化数据库
        self.db = Database()
        self.db.connect()
        self.db.init_database()
        
        # 初始化认证管理器
        self.auth_manager = AuthManager(self.root, self.db)
        
        # 初始化主界面
        self.main_ui = MainUI(self.root, self.db, self.auth_manager)
        
        # 显示登录窗口
        self.auth_manager.create_login_window(self.on_login_success)
    
    def on_login_success(self, user):
        """登录成功回调"""
        self.main_ui.set_current_user(user)
    
    def __del__(self):
        """析构函数，关闭数据库连接"""
        if hasattr(self, 'db'):
            self.db.close()

def main():
    root = tk.Tk()
    root.withdraw()  # 初始隐藏主窗口
    app = RabbitInfoSystem(root)
    root.mainloop()

if __name__ == "__main__":
    main()